layui.config({
    base: '../../static/layuiadmin/' //静态资源所在路径
}).extend({
    index: 'lib/index' //主入口模块
}).use(['form'], function() {
    var form=layui.form;
    var parentId=urlQuery("parentId");
    //监听提交
    form.on('submit(demo1)', function(data){
        var name=data.field.name;
        var url=data.field.url;
        if(name==null||name==""){
            layer.msg("菜单名称不能为空");
        }else {
            $.ajax({
                url:"/admin/menu/add",
                type:"post",
                data:{name:name,url:url,parentId:parentId},
                success:function (result) {
                    if (result.code==0){
                        layer.msg("添加成功！", {icon: 1,time:2000,shade:0.2});
                        setInterval(function () {
                            //当你在iframe页面关闭自身时
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index);
                            window.parent.location.reload();
                        },500)
                    }else {
                        layer.msg(result.message, {icon: 2,time:2000,shade:0.2});
                    }
                }
            });
        }
        return false;
    });
});